package com.scalar.chiptrack.operations.dataentry.dao;

import com.scalar.chiptrack.db.DataSource;
import com.scalar.chiptrack.operations.release.AssemblyRelease;
import com.scalar.chiptrack.utils.SqlQueryMappings;
import com.scalar.ScalarException;

import java.util.ArrayList;
import java.sql.*;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Aug 30, 2005
 * Time: 3:27:00 PM
 */
public class AssemblyDataEntryDAO {

    /**
     *
     * @param processStepId
     * @return
     * @throws ScalarException
     */
    public static ArrayList getAssemblyReleaseLotNumbers( String processStepId ) throws ScalarException
    {
        Connection conn = null;
        PreparedStatement cstmt = null;
        ResultSet rset = null;
        ArrayList assmLotNumbersList = new ArrayList();
        AssemblyRelease assmRelease = null;

        try
        {
            conn = DataSource.getConnection();

            cstmt = conn.prepareStatement(SqlQueryMappings.get("operations.testDataEntry.loadAssemblyReleases"));
            cstmt.setString( 1, processStepId );
            cstmt.setString( 2, processStepId );
            rset = cstmt.executeQuery();
            while( rset.next())
            {
                assmRelease = new AssemblyRelease();
                assmRelease.setAssemblyReleaseNo( rset.getString("ASSEMBLY_RELEASE_NO") );
                assmRelease.setLocation( rset.getString( "LOCATION") );
                assmRelease.setQtyPulled( rset.getInt("QTY_PULLED") );
                assmLotNumbersList.add( assmRelease );
            }
        }
        catch(SQLException sqle)
        {
            sqle.printStackTrace();
            throw new ScalarException( "Error While getting the Assembly Release Lot Details", sqle );
        }
        finally
        {
            if ( rset != null )
            {
                try { rset.close(); }catch ( SQLException ignore ){ }
            }
            if ( cstmt != null )
            {
                try { cstmt.close(); }catch ( SQLException ignore ){ }
            }
            if ( conn != null )
            {
                try { conn.close(); } catch( SQLException ignore ) { }
            }
        }
        return assmLotNumbersList;
    }


}
